
    class Solution {
        public static boolean isHappy(int n) {
            if(n == 1||sum_squares(n) == 1){
                return true;
            }
            int slow = sum_squares(n);
            int fast = sum_squares(sum_squares(n));
            while(slow != fast){
                slow = sum_squares(slow);
                fast = sum_squares(sum_squares(fast));
                if(slow == 1||fast == 1){
                    return true;
                }
            }

            return false;

        }
        public static int sum_squares(int n){
            int sum = 0;
            while(n!=0){
                int tmp = n % 10;
                sum = sum + tmp*tmp;
                n /= 10;
            }
            return sum;
        }
    }
    public class demo2 {
        public static void main(String[] args) {
            Solution s = new Solution();
            boolean a = s.isHappy(19);
            System.out.println(a);
        }
}
